package com.example.bookstore.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.example.bookstore.common.PageResult;
import com.example.bookstore.common.Result;
import com.example.bookstore.dto.OrdersRequest;
import com.example.bookstore.dto.QueryCartParamsDto;
import com.example.bookstore.dto.QueryOrderParamsDto;
import com.example.bookstore.entity.Cart;
import com.example.bookstore.entity.Orders;
import com.example.bookstore.service.OrderService;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    OrderService orderService;

    @PostMapping("/create")
    public Result createOrder(@RequestParam String type, @RequestBody OrdersRequest orders){
        return orderService.createOrders(orders,type);
    }
    @PostMapping("/page")
    public PageResult<Orders> selectByPageAndCondition(int pageSize, int currentPage, @RequestBody QueryOrderParamsDto params) {
        return orderService.selectByPageAndCondition(pageSize, currentPage, params);
    }
    @PostMapping
    public Orders getOrder(Integer ordersId){
        return orderService.getById(ordersId);
    }
    @PostMapping("/submit")
    private Result submitAddress(Integer ordersId,Integer addresseeId){
        return orderService.submitAddress(ordersId,addresseeId);
    }
    @GetMapping("/status")
    private Result updateStatus(Integer ordersId,String type){
        return orderService.updateStatus(ordersId,type);
    }
    @GetMapping("/appraise")
    private Result updateAppraise(Integer ordersId){
        return orderService.updateAppraise(ordersId);
    }
    @GetMapping("/address")
    public Result getOrderAddress(Integer ordersId){
       return orderService.getOrderAddress(ordersId);
    }
    @GetMapping("/detail")
    public Result getOrderDetail(Integer ordersId){
        return orderService.getOrderDetail(ordersId);
    }
    @DeleteMapping("/{id}")
    public Result cancelOrder(@PathVariable Integer id){
        return orderService.cancelOrder(id);
    }
}
